<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p>Dori says:</p>
    <p>It's only <span class="daysTill" id="bday"> </span> days until my birthday and <span class="daysTill" id="xmas"> </span> days until Christmas, so you'd better start shopping now!</p>
    <p>And it's only <span class="daysTill" id="anniv"> </span> days until our anniversary...</p>
    <script>
        window.addEventListener("load", showDays, false);

        function showDays() {
            var spanTags = document.getElementsByTagName("span");

            for (var i = 0; i < spanTags.length; i++) {
                if (spanTags[i].className.indexOf("daysTill") > -1) {
                    spanTags[i].innerHTML = showTheDaysTill(spanTags[i].id);
                }
            }

            function showTheDaysTill(thisDate) {
                var theDays;
                switch (thisDate) {
                    case "anniv":
                        theDays = daysTill(5, 6);
                        break;
                    case "bday":
                        theDays = daysTill(8, 7);
                        break;
                    case "xmas":
                        theDays = daysTill(12, 25);
                        break;
                    default:
                }
                return theDays + " ";
            }

            function daysTill(mm, dd) {
                var now = new Date();
                var inDate = new Date(now.getFullYear(), mm - 1, dd);

                if (inDate.getTime() < now.getTime()) {
                    inDate.setYear(now.getFullYear() + 1);
                }

                return Math.ceil(dayToDays(inDate) - dayToDays(now));
            }

            function dayToDays(inTime) {
                return inTime.getTime() / (1000 * 60 * 60 * 24);
            }
        }
    </script>
</body>

</html>